Conversation
commit: |
📝 WalkthroughWalkthroughThe change adjusts the lazy-load plugin so generated wrapper statements are inserted after the last import if any imports exist; if there are no imports, wrapper statements are still prepended at the top. Tests were updated to reflect the new ordering in emitted code. Files changed include the plugin implementation and unit test snapshots. Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@test/unit/hydration/lazy-hydration-plugin.test.ts`:
- Around line 182-183: The snapshot contains unnecessary escaped double quotes
(\" ) inside template literals causing no-useless-escape CI failures; update the
snapshots so the imports for __wrapImportedComponent, __wrapMainComponent and
useLazyComponentTracking use normal double quotes (") or switch the surrounding
template literal to single quotes so the escapes are not needed, i.e., replace
occurrences of \"import { __wrapImportedComponent, __wrapMainComponent } from
\\\"@nuxt/hints/runtime/lazy-load/composables\\\";\" and similar lines (and the
ones at the occurrences for useLazyComponentTracking) with unescaped quotes.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/unit/hydration/lazy-hydration-plugin.test.ts (1)
90-101: No test covers the "zero imports" fallback (prepend-at-top) code path.The
skipped importsdescribe block returnsundefinedearly for files without.vueimports, so the branch inlazy-load.tsthat prepends wrapper statements when there are no existing imports is not exercised by any snapshot test.Consider adding a case such as:
+ it('should prepend wrapper statements when there are no pre-existing imports', async () => { + const code = [ + `const _sfc_main = {}`, + `export default _sfc_main`, + ].join('\n') + // Manually inject a synthetic vue-import scenario or use a fixture + // that exercises the zero-import prepend path. + })Would you like me to draft the full test case, or open a new issue to track this coverage gap?
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/unit/hydration/lazy-hydration-plugin.test.ts` around lines 90 - 101, Add a new unit test in the "skipped imports" describe block that covers the "zero imports" fallback in lazy-load.ts: create code containing only a .vue import (e.g. `import MyComp from './MyComp.vue'\nexport default {}`), call the existing transform function (transform(code, '/src/Parent.vue')), and assert the transformed output exists and matches the snapshot (e.g. expect(result).toMatchSnapshot()) so the prepend-at-top branch in lazy-load.ts is exercised; place the test near the other cases referencing the same transform helper.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@test/unit/hydration/lazy-hydration-plugin.test.ts`:
- Around line 90-101: Add a new unit test in the "skipped imports" describe
block that covers the "zero imports" fallback in lazy-load.ts: create code
containing only a .vue import (e.g. `import MyComp from './MyComp.vue'\nexport
default {}`), call the existing transform function (transform(code,
'/src/Parent.vue')), and assert the transformed output exists and matches the
snapshot (e.g. expect(result).toMatchSnapshot()) so the prepend-at-top branch in
lazy-load.ts is exercised; place the test near the other cases referencing the
same transform helper.
🔗 Linked issue
#241
📚 Description
avoid TMZ violation. bug doesn't happen client side but vite can replace imports with __vite_ssr_import in SSR code which then can cause a TMZ violation